//
//  MSTagsView.m
//  MSJD
//
//  Created by xiangbo on 2018/12/15.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSTagsView.h"

@implementation MSTagsView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.image = [[UIImageView alloc] init];
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        self.titleLabel.textColor = UIColorHex(0x444444);
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.image];
        [self addSubview:self.titleLabel];
        
        [self.image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(32);
            make.centerX.equalTo(self);
            make.top.equalTo(self).offset(10);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self);
            make.top.equalTo(self.image.mas_bottom).offset(8);
            make.centerX.equalTo(self);
            make.height.mas_equalTo(12);
        }];
    }
    return self;
}

- (void)configData:(id)data indexPath:(NSIndexPath *)indexPath{
    self.modelData = data;
}

- (void)setModelData:(id)modelData{
    NSString *imageUrl = @"";
    NSString *title = @"";
    if ([modelData isKindOfClass:MSFoodContentModel.class]) {
        MSFoodContentModel *model = modelData;
        imageUrl = model.cover;
        title = model.title;
    }
    [self.image setImageWithURL:[NSURL URLWithString:imageUrl] placeholder:MSPlaceholderImg];
    self.titleLabel.text = title;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
